/*
 * @Author: hongbin
 * @Date: 2022-11-25 11:28:54
 * @LastEditors: hongbin
 * @LastEditTime: 2022-11-25 18:28:10
 * @Description:初始化个人配置数据
 */
import { ObjectId } from "mongodb";
import { NextApiRequest, NextApiResponse } from "next";
import DB from "../mongodb";

export default async function handler(req: NextApiRequest, res: NextApiResponse<any>) {
    const db = await DB;
    const { id } = req.query;
    if (!id) return res.status(501).json({ code: -1, msg: "未传递参数id" });

    const config = {
        userId: new ObjectId(id as string),
        current: "config1",
        config1: { wearParts: [] },
        config2: { wearParts: [] },
        config3: { wearParts: [] },
    };

    const init = await db.collection("partsConfig").insertOne(config);
    console.log("初始化用户配件配置", init);
    res.json(init);
}
